How do I access column data in a previous select statement from a sub-query? [closed]
Posted
by
payling
on Pro Webmasters
See other posts from Pro Webmasters
or by payling
Published on 2011-02-22T16:34:26Z
Indexed on
2011/02/22
23:34 UTC
Read the original article
Hit count: 249
mysql
PROBLEM
How do I access column data in a previous select statement from a sub-query?
Below is a simple mock up of what I'm attempting to do.
Tables used: Quotes, Users
QUOTES TABLE
qid, (quote id)
owner_uid,
creator_uid
SQL SYNTAX:
SELECT q.qid, q.owner_uid, q.creator_uid, owner.fname, owner.lname FROM quotes q, (SELECT u.fname, u.lname FROM users u WHERE u.uid = q.owner_uid) AS owner WHERE q.qid = '#'
SUMMARY
I want to be able to use the quote table's owner_uid and specify it for the owner table so I can return all the owner info for that particular quote.
The problem is, q.owner_uid is not recognized in the owner sub-query. What am I doing wrong?
© Pro Webmasters or respective owner